<template>
  <div class="info_config_page">
    <div class="common_form_search">
      <el-form ref="searchForm" :inline="true" :model="searchForm" class="form-inline">
        <el-form-item label="订单号">
          <el-input v-model="searchForm.orderNo" placeholder="请输入订单号" />
        </el-form-item>
        <!-- <el-form-item label="租户ID">
          <el-input
            v-model="searchForm.pay_id"
            placeholder="请输入租户ID"
          ></el-input>
        </el-form-item> -->
        <el-form-item label="物流单号">
          <el-input v-model="searchForm.number" placeholder="请输入物流单号" />
        </el-form-item>
        <el-form-item label="物流名称">
          <el-input v-model="searchForm.name" placeholder="请输入物流名称" />
        </el-form-item>
        <el-form-item label="物流状态">
          <el-select v-model="searchForm.logisticsStatus" clearable placeholder="请选择">
            <el-option :value="-1" label="未发货" />
            <el-option :value="1" label="已发货" />
            <!-- <el-option :value="3" label="运输中"></el-option> -->
            <el-option :value="3" label="已签收" />
            <!-- <el-option :value="0" label="其他"></el-option> -->
          </el-select>
        </el-form-item>
        <el-form-item label="上链状态">
          <el-select v-model="searchForm.status" clearable placeholder="请选择">
            <el-option :value="0" label="未上链" />
            <el-option :value="1" label="已上链" />
          </el-select>
        </el-form-item>
        <el-form-item label="发货时间">
          <my-date-picker ref="myDatePicker1" />
        </el-form-item>
        <el-form-item label="签收时间">
          <my-date-picker ref="myDatePicker2" />
        </el-form-item>
        <!-- <el-form-item label="供应商">
          <el-input
            v-model="searchForm.cert_no"
            placeholder="请输入供应商"
          ></el-input>
        </el-form-item> -->
        <el-form-item>
          <el-button size="small" @click="search()" type="primary">查询</el-button>
          <el-button size="small" @click="reset()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-divider />
    <div class="flex align-center table-top-btns">
      <h5 class="flex align-center">
        <svg-icon style="margin-right: 15px" icon-class="list" :size="15" />数据列表
      </h5>
    </div>
    <el-table :data="tableData" border>
      <el-table-column align="center" header-align="center" fixed prop="id" label="ID" width="60" />
      <el-table-column align="center" header-align="center" fixed prop="order_no" label="订单ID" width="200" />
      <!-- <el-table-column
        align="center"
        header-align="center"
        prop="order_id"
        label="租户ID"
        width="110"
      /> -->
      <el-table-column align="center" header-align="center" prop="logistics_status" label="物流状态" width="110">
        <template slot-scope="scope">
          <span>
            {{ scope.row.logistics_status == -1 ? "未发货" : scope.row.logistics_status == 1 ? "已发货" : scope.row.logistics_status == 2 ? "运输中" : scope.row.logistics_status == 3 ? "已签收" : "其他" }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" fixed prop="logistics_name" label="物流公司" width="120" />
      <el-table-column align="center" header-align="center" label="物流单号">
        <template slot-scope="scope">
          <span>{{ scope.row.logistics_no != 0 ? scope.row.logistics_no : '无' }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" prop="deliver_time" label="发货时间" width="100" />
      <el-table-column align="center" header-align="center" prop="confirm_time" label="签收时间" width="100" />
      <!-- <el-table-column
        align="center"
        header-align="center"
        prop="lease_status"
        label="是否退租"
        width="100"
      />
      <el-table-column
        align="center"
        header-align="center"
        prop="member_id"
        label="供应商"
      >
      </el-table-column> -->
      <el-table-column align="center" header-align="center" prop="chain_time" width="100" label="上链时间" />
      <el-table-column align="center" header-align="center" prop="chain_status" label="上链状态" width="100">
        <template slot-scope="scope">
          <el-tag class="pointer" :type="scope.row.user_chain_status === 0 ? 'primary' : 'success'" @click="getParams(scope.row.chain_params)" disable-transitions>
            {{ scope.row.user_chain_status == 0 ? "未上链" : "已上链" }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <div class="operate_col">
            <!-- @click="$router.push({path:'/logisticsH5', query: {orderNo: scope.row.order_no}})" -->
            <el-button @click="jumpLogistics(scope.row.order_no)" type="primary" size="small">
              物流记录
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <custom-page ref="customPage" :total="total" @getList="getList" />
    <param-dialog :dialogVisible="dialogVisible" :dialogType="dialogType" :requestInfo="requestInfo" :responseInfo="responseInfo" @close="closeDialog" />
  </div>
</template>

<script>
import { getLogisticsList } from '@/api/lease'
import customPage from '@/components/customPage'
import myDatePicker from '@/components/myDatePicker'
import paramDialog from './child/paramDialog.vue'
export default {
  components: { customPage, myDatePicker, paramDialog },
  data() {
    return {
      tableData: [],
      total: 0,
      searchForm: {
        orderNo: '',
        number: '',
        name: '',
        logisticsStatus: '',
        status: '',
        deliverTime: '',
        confirmTime: ''
      },
      dialogVisible: false,
      dialogType: 1,
      requestInfo: {},
      responseInfo: {}
    }
  },
  methods: {
    search() {
      const pickerVal1 = this.$refs.myDatePicker1.getVal()
      const pickerVal2 = this.$refs.myDatePicker2.getVal()
      if (pickerVal1 !== 'error' || pickerVal2 !== 'error') {
        this.searchForm.deliverTime = pickerVal1
        this.searchForm.confirmTime = pickerVal2
        this.$refs.customPage.page = 1
        this.getList()
      }
      this.$refs.customPage.page = 1
      this.getList()
    },
    // 重置
    reset() {
      if (this.$refs.myDatePicker1) {
        this.$refs.myDatePicker1.reset()
      }
      if (this.$refs.myDatePicker2) {
        this.$refs.myDatePicker2.reset()
      }
      this.searchForm = Object.assign({})
      this.getList();
    },
    jumpLogistics(num) {
      const { href } = this.$router.resolve({
        path: '/logisticsH5',
        query: { orderNo: num }
      });
      window.open(href, '_blank')
    },
    getParams(row) {
      this.dialogType = 2
      this.dialogVisible = true
      let info = JSON.parse(row)
      this.requestInfo = info.request ? JSON.parse(info.request.biz_content) : {}
      this.responseInfo = info.response ? info.response : {}
    },
    closeDialog() {
      this.dialogVisible = false
    },
    getList() {
      const { page, pageSize } = this.$refs.customPage
      getLogisticsList({
        page,
        pageSize,
        ...this.searchForm
      }).then((res) => {
        this.tableData = res.data
        this.total = res.total
      })
    }
  },
  mounted() {
    this.getList()
  },
}
</script>

<style lang="scss" scoped>
</style>
